package ahxu.commons.fileupload;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

public class ResponsePushProcessListener extends AbstractAhxuProgressListener {
	private HttpServletResponse response;
	private String threadId;
	public ResponsePushProcessListener(ReportItem item,HttpServletResponse response,String threadId) {
		super(item);
		this.response=response;
	}

	@Override
	public void updateDo(ReportItem reportItem) {
		response.setBufferSize(0);
		try {
			PrintWriter pw=response.getWriter();
			pw.println("<script type=\"text/javascript\" language=\"javascript\">");
			pw.println("window.parent.uploadProcess.update('"+this.threadId+"','"+reportItem.getStartTime()+"','"+reportItem.getUploadTime()+"','"+reportItem.getTotalSize()+"','"+reportItem.getUploadSize()+"','"+reportItem.getUploadFileSum()+"','"+reportItem.getUploadedFileSum()+"');");
			pw.println("</SCRIPT>");
			pw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
